package com.example.lifecycle;

import com.example.lifecycle.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class MainAbility extends Ability {
    static final HiLogLabel loglabel = new HiLogLabel(HiLog.LOG_APP, 0x00101, "MainAbility");
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(MainAbilitySlice.class.getName());
        HiLog.info(loglabel, "onStart");

        if (getLastStoredDataWhenConfigChanged() != null) {
            // 获取存储的数据对象
            String data = getLastStoredDataWhenConfigChanged().toString();
            HiLog.info(loglabel, data);
        }

    }

    @Override
    protected void onActive() {
        super.onActive();
        HiLog.info(loglabel, "onActive");
    }

    @Override
    protected void onForeground(Intent intent) {
        super.onForeground(intent);
        HiLog.info(loglabel, "onForeground");
    }

    @Override
    protected void onBackground() {
        super.onBackground();
        HiLog.info(loglabel, "onBackground");
    }

    @Override
    protected void onInactive() {
        super.onInactive();
        HiLog.info(loglabel, "onInactive");
    }

    @Override
    protected void onStop() {
        super.onStop();
        HiLog.info(loglabel, "onStop");
    }

    @Override
    public Object onStoreDataWhenConfigChange() {
        return "需要存储的数据，转换为Object对象";
    }

}
